package com.zlkj.pro.core.util;

import cn.hutool.core.util.StrUtil;

/**
 * @author 孙铭泽
 * @date 2022/10/28
 * @time 15:02
 */
public class StrUtils {

    public static String valueOf(Object obj) {
        return (obj == null) ? "" : obj.toString();
    }

    public static String camelToUnderscore(String input) {
        if (StrUtil.isEmpty(input)) {
            return input;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (Character.isUpperCase(c) && i > 0) {
                sb.append('_');
            }
            sb.append(Character.toLowerCase(c));
        }
        return sb.toString();
    }
}
